﻿using JT808.Gateway.Abstractions;
using JT808.Gateway.RabbitMQ.Configs;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace JT808.Gateway.RabbitMQ
{
    public static class JT808ServerRabbitExtensions
    {
        public static IJT808GatewayBuilder AddServerRabbitNotifyConsumer(this IJT808GatewayBuilder builder, IConfiguration configuration)
        {
            builder.JT808Builder.Services.Configure<JT808NotifyConsumerConfig>(configuration.GetSection("JT808RabbitNotifyConsumerConfig"));
            builder.JT808Builder.Services.Replace(new ServiceDescriptor(typeof(IJT808NotifyConsumer), typeof(JT808NotifyConsumer), ServiceLifetime.Singleton));
            return builder;
        }

        public static IJT808GatewayBuilder AddServerRabbitResponseProducer(this IJT808GatewayBuilder builder, IConfiguration configuration)
        {
            builder.JT808Builder.Services.Configure<JT808ApiResponseProducerConfig>(configuration.GetSection("JT808RabbitApiResponseProducerConfig"));
            builder.JT808Builder.Services.Replace(new ServiceDescriptor(typeof(IJT808ApiResponseProducer), typeof(JT808ApiResponseProducer), ServiceLifetime.Singleton));
            return builder;
        }

        public static IJT808GatewayBuilder AddServerRabbitResponseConsumer(this IJT808GatewayBuilder builder, IConfiguration configuration)
        {
            builder.JT808Builder.Services.Configure<JT808ApiResponseConsumerConfig>(configuration.GetSection("JT808RabbitApiResponseConsumerConfig"));
            builder.JT808Builder.Services.TryAddSingleton<IJT808ApiResponseConsumer, JT808ApiResponseConsumer>();
            return builder;
        }
        public static IJT808GatewayBuilder AddServerRabbitMsgProducer(this IJT808GatewayBuilder builder, IConfiguration configuration)
        {
            builder.JT808Builder.Services.Configure<JT808MsgProducerConfig>(configuration.GetSection("JT808RabbitMsgProducerConfig"));
            builder.JT808Builder.Services.Replace(new ServiceDescriptor(typeof(IJT808MsgProducer), typeof(JT808MsgProducer), ServiceLifetime.Singleton));
            return builder;
        }
        public static IJT808GatewayBuilder AddServerRabbitMsgReplyConsumer(this IJT808GatewayBuilder builder, IConfiguration configuration)
        {
            builder.JT808Builder.Services.Configure<JT808MsgReplyConsumerConfig>(configuration.GetSection("JT808RabbitMsgReplyConsumerConfig"));
            builder.JT808Builder.Services.Replace(new ServiceDescriptor(typeof(IJT808MsgReplyConsumer), typeof(JT808MsgReplyConsumer), ServiceLifetime.Singleton));
            return builder;
        }
        public static IJT808GatewayBuilder AddServerRabbitSessionProducer(this IJT808GatewayBuilder builder, IConfiguration configuration)
        {
            builder.JT808Builder.Services.Configure<JT808SessionProducerConfig>(configuration.GetSection("JT808RabbitSessionProducerConfig"));
            builder.JT808Builder.Services.Replace(new ServiceDescriptor(typeof(IJT808SessionProducer), typeof(JT808SessionProducer), ServiceLifetime.Singleton));
            return builder;
        }
    }
}
